package com.fpt.app.demo.task;

import java.io.IOException;

import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.Environment;
import android.util.Log;

public class AudioTask {
	private MediaRecorder mRecorder;
	private static String mFileName = null;
	private long mMaxAmp;
	
	public AudioTask() {
		 mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
	     mFileName += "/audiorecordtest.3gp";
	     Log.e("Linhnv","Filename : " + mFileName);
	     
	}
	public void startRecording() {
		mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL|MediaRecorder.AudioSource.MIC|MediaRecorder.AudioSource.VOICE_DOWNLINK |MediaRecorder.AudioSource.VOICE_UPLINK);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setOutputFile(mFileName);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);        
        try {
            mRecorder.prepare();
        } catch (IOException e) {
            Log.e("Linhnv", "prepare() failed");
        }
        mRecorder.start();
        mRecorder.getMaxAmplitude();
        
    }
	public void resetRecording(){
		mMaxAmp =mRecorder.getMaxAmplitude();
        mRecorder.stop();
        
        mRecorder.reset();
//        setmMaxAmp(mMaxAmp);
        Log.e("Linhnv", "Max Amp :" + mMaxAmp);
	}
	
	public void stopRecording() {
		//long maxAmp =mRecorder.getMaxAmplitude();
        mRecorder.stop();       
        mRecorder.release();
//        Log.e("Linhnv", "Max Amp :" + maxAmp);
//        mRecorder = null;
    }
	public long getmMaxAmp() {
		return mMaxAmp;
	}
	public void setmMaxAmp(long mMaxAmp) {
		this.mMaxAmp = mMaxAmp;
	}
	
}
